import BuffUtil from '@/BuffUtil';
import MathUtil from '@/MathUtil';
import SelectUtil from '@/SelectUtil';
import BuffCommon from 'code/Core/Common/BuffCommon';
import MovementCommon from 'code/Core/Common/MovementCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 震荡波
 **/
export default class ZS_ShockWave extends AbilityBase {
    static instance: ZS_ShockWave;
    buffType: AppBuffType = {
        id: 'buff_ZS_ShockWave',
        art: this.art,
        name: this.abilityName,
        ubertip: '命中，闪避下降',
        dur: 6,
        targetAttach: 'origin',
        targetArt: 'Abilities\\Spells\\Human\\Thunderclap\\ThunderclapTarget.mdl',
        attribute: {},
    };
    constructor(id: string = 'Azdb') {
        super(id);
        ZS_ShockWave.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    init() {
        BuffUtil.registerBuffType(this.buffType);
    }
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        let ux = GetUnitX(source);
        let uy = GetUnitY(source);
        let ag = MathUtil.angleBetweenCoords(ux, uy, tarX, tarY);
        MovementCommon.LineMissile({
            missile: 'Abilities\\Spells\\Orc\\Shockwave\\ShockwaveMissile.mdl',
            caster: source,
            is_through: true,
            distance: 600,
            time: 0.6,
            angle: ag,
            onHit: this.onHit.bind(this),
            onFinish: this.onEnd.bind(this),
        });
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
    pool: Map<unit, unit[]> = new Map();
    onHit(p: LineMissileConfig, hit: unit) {
        let es = SelectUtil.getEnemyUnitsInRange(p.caster, 175, p.curX, p.curY);
        let 池 = this.pool.get(p.caster);
        if (!池) {
            池 = [];
            this.pool.set(p.caster, 池);
        }
        let lv = this.getAbilityLevel(p.caster);
        let dmg = 35 * lv + UnitCommon.取攻击(p.caster) * (0.75 + 0.25 * lv);
        for (let e of es) {
            if (!池.includes(e)) {
                池.push(e);
                DamageSystemInstance.applyWindDamage(e, p.caster, dmg, this.id);
                // let buff = BuffUtil.addBuff(e, this.buffType.id, p.caster);
                // buff.attribute.命中 = -0.1 + 0.05 * lv;
                // buff.attribute.基础闪避 = -0.1 + 0.05 * lv;
                BuffCommon.addBuff({
                    target: e,
                    caster: p.caster,
                    buffTypeId: this.buffType.id,
                    ablityId: this.id,
                    attribute: { 命中: -0.1 + 0.05 * lv, 基础闪避: -0.1 + 0.05 * lv },
                });
            }
        }
    }
    onEnd(p: LineMissileConfig) {
        this.pool.delete(p.caster);
    }
}
